package com.tywj.buscustomerapp.model;

import android.util.Log;

import com.amap.api.maps.model.LatLng;
import com.tywj.buscustomerapp.model.bean.StationBean;
import com.tywj.buscustomerapp.presenter.contract.MapTicketContract;
import com.tywj.buscustomerapp.utils.WebServicrUtils;

import org.xmlpull.v1.XmlPullParserException;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class MapTicketModel implements MapTicketContract.MapTicketModel{
    @Override
    public List<StationBean> loadStation(String stationId) {
        String stringIo = null;
        List<StationBean> beans = null;
        try {
            stringIo = WebServicrUtils.getInstance().getTravelLineInfo(stationId);
            InputStream in_nocode = new ByteArrayInputStream(stringIo.getBytes("UTF-8"));
            beans = WebServicrUtils.getInstance().getStations(in_nocode);
            return beans;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return beans;
    }

    @Override
    public LatLng getBusLocation(String lineNumber, String city) {
        LatLng latLng = null;
        try {
            String msg  = WebServicrUtils.getInstance().getBusLocation(lineNumber,city);
            InputStream in_nocode = new ByteArrayInputStream(msg.getBytes("UTF-8"));
            latLng = WebServicrUtils.getInstance().getBusLocation(in_nocode);
            Log.i("taylor",msg);
            return latLng;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return latLng;
    }
}
